package token

import (
	"encoding/json"
	"time"
)

type output struct {
	Code    uint   `json:"code"`
	Msg     string `json:"msg"`
	Time    int64  `json:"time"`
	Payload string `json:"payload"`
}

func printErr(err error, code uint) {
	o := &output{
		Code:    code,
		Msg:     err.Error(),
		Time:    time.Now().Unix(),
		Payload: "",
	}
	printOut(o)
}

func printOk(payload string) {
	o := &output{
		Code:    0,
		Msg:     "",
		Time:    time.Now().Unix(),
		Payload: payload,
	}
	printOut(o)
}

func printOut(o *output) {
	s, err := json.Marshal(o)
	if err != nil {
		println(err.Error())
	}
	println(string(s))
}
